<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>编辑文档</title>
<link href="/css/admin.css" rel="stylesheet" type="text/css" />
<script src="/js/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="/js/ckeditor/ckeditor.js" type="text/javascript" ></script>
<script src="/js/ckfinder/ckfinder.js" type="text/javascript"></script>
<style type="text/css">
	.longtxt{width:400px;}
	.handimg{cursor:pointer;}
</style>
<script>
	var attnum = 100;
	$(function () {
		var editor = CKEDITOR.replace( 'acontent' );
		CKFinder.setupCKEditor( editor, '/js/ckfinder/' ) ;

		var arttype = '<?=$atype?>';
		
		if(arttype == '0'){
			$("#radio0").attr("checked","true");
		}
		else if(arttype == '1'){
			$("#radio1").attr("checked","true");

			$("#div_content").css('display','none');
			$("#div_att").css('display','');
			$("#div_hylink").css('display','none');
			$("#contentTitle").text('附件');
		}
		else if(arttype == '2'){
			$("#radio2").attr("checked","true");
			
			$("#div_content").css('display','none');
			$("#div_att").css('display','none');
			$("#div_hylink").css('display','');
			$("#contentTitle").text('链接地址');
		}
		else
			$("#radio0").attr("checked","true");

		var thumburl = '<?=$titlethumbs?>';
		if(thumburl != ''){
			thumburl = thumburl.replace("/images/","/_thumbs/images/");
			$("#preview").html("<img src='" + thumburl + "' />");
			$("#preview").css('display','');
		}
	});

	function clearTitlethumb(){
		$("#titlethumbs").val('');
		$("#preview").html('');
		$("#preview").css('display','none');
	}
	function BrowseServer( ){		
		var finder = new CKFinder();
		finder.startupPath = 'Images:/';		
		finder.selectActionFunction = SetFileField;
		//finder.selectActionData = 'titlethumbs';		
		//finder.selectThumbnailActionFunction = MyShowThumbnails;
		finder.popup();
	}

	function SetFileField( fileUrl ){
		//var sFileName = this.getSelectedFile().name;
		$("#titlethumbs").val(fileUrl);		
		var thumburl = fileUrl.replace("/images/","/_thumbs/images/");//fileUrl;//
		$("#preview").html('<img src="' + thumburl + '" />');
		$("#preview").css('display','');
	}

	function BrowseServer2( ){		
		var finder = new CKFinder();
		finder.startupPath = 'Files:/';		
		finder.selectActionFunction = SetFileField2;
		//finder.selectActionData = 'titlethumbs';		
		//finder.selectThumbnailActionFunction = MyShowThumbnails;
		finder.popup();
	}

	function SetFileField2( fileUrl ){
		//var sFileName = this.getSelectedFile().name;
		//$("#attname").val(sFileName);		
		$("#atturl").val(fileUrl);
	}

	function BrowseServer3( ){
		window.open("/MyUpload/",'Upload','width=300,height=200,left=' + (screen.availWidth - 300) / 2 + ',top=' + (screen.availHeight - 200) / 2);
	}

	function appendatt(fname){		
		attnum++;
		fname = unescape(fname);
		$("#div_attlist").append("<p><a href='/upfiles/files/" + fname + "' target='_blank'>" + fname + "</a>&nbsp;&nbsp;&nbsp;&nbsp;<input type='hidden' name='attlist_0_" + attnum + "' value='" + fname + "' /><a href=\"#\" onclick=\"javascript:delatt(this);\">删除</a></p>");
	}

	function delatt(obj){
		$(obj).parent().remove();
	}

	function changeAtype(){
		if($("#radio0").attr("checked") == true)
		{				
			$("#div_content").css('display','');
			$("#div_att").css('display','none');
			$("#div_hylink").css('display','none');
			$("#contentTitle").text('内容');
			
		}
		if($("#radio1").attr("checked") == true)
		{
			$("#div_content").css('display','none');
			$("#div_att").css('display','');
			$("#div_hylink").css('display','none');
			$("#contentTitle").text('附件');
		}
		if($("#radio2").attr("checked") == true)
		{
			$("#div_content").css('display','none');
			$("#div_att").css('display','none');
			$("#div_hylink").css('display','');
			$("#contentTitle").text('链接地址');
		}
	}

	function VerifyPage(){
		if($("#title").val()==''){
			alert('标题不能为空!');
			return false;
		}
		return true;
	}
	function MyGoBack(cid){
		window.location = "/cms/articles/" + cid;
	}

	function chooseTpl(){
		window.open('/cms/choosetpl/article','','width=350,height=350,left=' + (screen.availWidth - 350) / 2 + ',top=' + (screen.availHeight - 350) / 2);
	}
	function settpl(parm){		
		var ary = parm.split('|');
		if(ary.length == 2){
			var tid = ary[0];
			var tname = ary[1];
			$("#tname").val(tname);
			$("#tid").val(tid);
		}
	}
</script>
</head>
<body>
<form name="form1" action="/cms/saveart" method="post" onSubmit="return VerifyPage();">
<input type="hidden" name="cid" value="<?=$cid?>" />
<input type="hidden" name="aid" value="<?=$aid ?>" />
<div class="listTitle">编辑文档</div>
<div>
<table cellpadding="3">
<tr><td nowrap>类型</td><td><input type="radio" id="radio0" id="atype0" name="atype" value="0"  onclick="changeAtype()" />文章 <input type="radio" id="radio1" id="atype1" name="atype" value="1" onclick="changeAtype()" />附件 <input type="radio" id="radio2" id="atype2" name="atype" value="2" onclick="changeAtype()" />超链接 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="display1" name="display" value="1" <?php if($display==1)echo('checked');?> />隐藏</td></tr>
<tr><td>标题</td><td ><input type="text" class="longtxt" id="title" name="title" value="<?=$title?>" /></td><td align="right">标题图片</td><td valign="middle"><span id="preview" style="display:none;"></span><a href="javascript:BrowseServer();">添加</a>&nbsp;&nbsp;<a href="javascript:clearTitlethumb()">清除</a><input type="hidden" id="titlethumbs" name="titlethumbs" value="<?=$titlethumbs?>" /></td></tr>
<tr><td><span id="contentTitle">内容</span></td><td colspan="3"><div id="div_content"><textarea id="acontent" name="acontent" rows="20"><?=$acontent?></textarea></div><div id="div_att" style="display:none;"><input type="text" id="atturl" name="atturl" value="<?=$atturl?>" /><input type="button" value="选择附件" onclick="BrowseServer2()"/></div><div id="div_hylink" style="display:none;"><input type="text" class="longtxt" id="linkurl" name="linkurl" value="<?=$linkurl?>" /></div></td></tr>
<tr><td>作者</td><td ><input type="text" id="author" name="author" value="<?=$author?>" /></td><td>关键字</td><td><input type="text" id="keyword" name="keyword" value="<?=$keyword?>" /></td></tr>
<tr><td>权重</td><td ><input type="text"  id="sortno" name="sortno" value="<?=$sortno?>" /><font color="#008080">&nbsp;(越小越靠前)</font></td><td>模板</td><td><input type="text" id="tname" name="tname" value="<?=$tname?>" /><input type="hidden" id="tid" name="tid" value="<?=$tid?>" /><input type="button" value="..." onclick="chooseTpl()"></td></tr>
<tr><td valign="top">附件</td><td colspan="3"><a href="javascript:BrowseServer3()">添加附件</a><div id="div_attlist"><?=$attlist?></div></td></tr>
<tr><td></td><td><input type="submit" value=" 保存 " <?php if(!$editable)echo("disabled");?> />&nbsp;&nbsp;<?php if($popup == ''){?><input type="button" value="返回" onclick="MyGoBack('<?=$cid?>');" /><?php }?><input type="hidden" id="hidpopup" name="hidpopup" value="<?=$popup?>"></td></tr>
</table>
</div>
</form>
</body>
</html>
